package com.ruoyi.storeroomuse.aspect;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.storeroomuse.service.IStoreroomUseService;
import com.ruoyi.storeroomuse.vo.StoreUseVO;
import com.ruoyi.system.service.IStoreroomService;
import com.ruoyi.system.vo.StoreroomAndUserVO;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class StoreDeleteAspect {

    @Autowired
    IStoreroomUseService storeroomUseService;

    @Autowired
    IStoreroomService storeroomService;

    @Pointcut("execution(public * com.ruoyi.system.service.IStoreroomService.delete*(..))")
    public void myMethod(){
        //代理方法
    }
    @After("myMethod()")
    public void afterMethod(JoinPoint joinPoint){
        Object[] args = joinPoint.getArgs();
        for (Object every : args) {
            if (every instanceof String){
                String eve=(String) every;
                String[] strings = Convert.toStrArray(eve);
                for (String str: strings) {
                    StoreUseVO storeUseVO = new StoreUseVO();
                    StoreroomAndUserVO storeroomAndUserVO = storeroomService.selectStoreroomByStoreroomId(Long.parseLong(str));
                    storeUseVO.setStoreroomId(storeroomAndUserVO.getStoreroomId());
                    SysUser sysUser = ShiroUtils.getSysUser();
                    storeUseVO.setFounder(sysUser.getUserId());
                    storeUseVO.setOperationName(1L);
                    storeroomUseService.insertStoreroomUse(storeUseVO);
                }
            }
        }
    }
}
